
import pandas as pd
import numpy as np
from matplotlib import pyplot as plt
from matplotlib.pyplot import figure
import seaborn as sn
from azureml.core import Workspace, Dataset

subscription_id = 'XXX'
resource_group = 'XXX'
workspace_name = 'XXX'

# Get workspace info based on subscription id, resource group, and workspace name
workspace = Workspace(subscription_id, resource_group, workspace_name)

'''
Four operations related to Azure ML workspace
1 - Get workspace info based on subscription id, resource group, and workspace name
workspace = Workspace(subscription_id, resource_group, workspace_name)

2 - List all workspaces in subscription id
print("List all workspaces in your subscription: {0}".format(Workspace.list(subscription_id)))

3 - Create workspace
ws = Workspace.create(name='myworkspace',
    subscription_id='XXX',
    resource_group='XXX',
    create_resource_group=True,
    location='eastus2'
    )

4 - delete workspace
# workspace.delete(delete_dependent_resources=False, no_wait=False)
'''

# get the datastore to upload prepared data
datastore = workspace.get_default_datastore()

# upload the local file from src_dir to the target_path in datastore. You will 
datastore.upload(src_dir='../2-dataPreprocess/Dataset', target_path='data')

dataset = Dataset.Tabular.from_delimited_files(datastore.path('data/weather_dataset_processed.csv'))
training_dataset = Dataset.Tabular.from_delimited_files(datastore.path('data/training_data.csv'))
validation_dataset = Dataset.Tabular.from_delimited_files(datastore.path('data/validation_data.csv'))

print("preview the first 3 rows of the dataset from datastore: ", dataset.take(3).to_pandas_dataframe())

# Register Dataset to workspace
weather_ds = dataset.register(workspace=workspace,
                name='processed_weather_dataset',
                description='processed weather data')
training_ds = training_dataset.register(workspace=workspace,
                name='training_dataset',
                description='Dataset to use for ML training')
validation_ds = validation_dataset.register(workspace=workspace,
                name='validation_dataset',
                description='Dataset for validation ML models')
